home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch12 / wave.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-08-24  |  18.7 KB  |  587 lines

  1. VERSION 4.00
  2. Begin VB.Form frmWave 
  3.    BackColor       =   &H00008000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "The Wave Program"
  6.    ClientHeight    =   5175
  7.    ClientLeft      =   645
  8.    ClientTop       =   1785
  9.    ClientWidth     =   7215
  10.    Height          =   5865
  11.    Icon            =   "WAVE.frx":0000
  12.    Left            =   585
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   345
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   481
  18.    Top             =   1155
  19.    Width           =   7335
  20.    Begin VB.CommandButton cmdDelete 
  21.       Caption         =   "&Delete"
  22.       Height          =   615
  23.       Left            =   6000
  24.       TabIndex        =   7
  25.       Top             =   4560
  26.       Width           =   1215
  27.    End
  28.    Begin VB.CommandButton cmdRecord 
  29.       Caption         =   "&Record"
  30.       Height          =   615
  31.       Left            =   4800
  32.       TabIndex        =   5
  33.       Top             =   4560
  34.       Width           =   1215
  35.    End
  36.    Begin VB.CommandButton cmdEndOfFile 
  37.       Caption         =   "&End of File"
  38.       Height          =   615
  39.       Left            =   3600
  40.       TabIndex        =   3
  41.       Top             =   4560
  42.       Width           =   1215
  43.    End
  44.    Begin VB.CommandButton cmdRewind 
  45.       Caption         =   "&Rewind"
  46.       Height          =   615
  47.       Left            =   2400
  48.       TabIndex        =   2
  49.       Top             =   4560
  50.       Width           =   1215
  51.    End
  52.    Begin VB.CommandButton cmdStop 
  53.       Caption         =   "&Stop"
  54.       Height          =   615
  55.       Left            =   1200
  56.       TabIndex        =   1
  57.       Top             =   4560
  58.       Width           =   1215
  59.    End
  60.    Begin VB.CommandButton cmdPlay 
  61.       Caption         =   "&Play"
  62.       Height          =   615
  63.       Left            =   0
  64.       TabIndex        =   0
  65.       Top             =   4560
  66.       Width           =   1215
  67.    End
  68.    Begin VB.Label lblRecording 
  69.       BackColor       =   &H00008000&
  70.       Caption         =   "Recording in progress..."
  71.       BeginProperty Font 
  72.          name            =   "MS Sans Serif"
  73.          charset         =   0
  74.          weight          =   400
  75.          size            =   29.25
  76.          underline       =   0   'False
  77.          italic          =   0   'False
  78.          strikethrough   =   0   'False
  79.       EndProperty
  80.       ForeColor       =   &H00000080&
  81.       Height          =   735
  82.       Left            =   600
  83.       TabIndex        =   6
  84.       Top             =   0
  85.       Visible         =   0   'False
  86.       Width           =   6495
  87.    End
  88.    Begin TegoswLibCtl.Tegosw swExit 
  89.       Height          =   630
  90.       Left            =   0
  91.       TabIndex        =   4
  92.       Top             =   0
  93.       Width           =   525
  94.       _version        =   65536
  95.       _extentx        =   926
  96.       _extenty        =   1111
  97.       _stockprops     =   64
  98.       value           =   -1  'True
  99.    End
  100.    Begin MSComDlg.CommonDialog CommonDialog1 
  101.       Left            =   3240
  102.       Top             =   2760
  103.       _Version        =   65536
  104.       _ExtentX        =   847
  105.       _ExtentY        =   847
  106.       _StockProps     =   0
  107.       CancelError     =   -1  'True
  108.    End
  109.    Begin TegowavLib.TegoWav TegoWav1 
  110.       Height          =   600
  111.       Left            =   3000
  112.       TabIndex        =   8
  113.       Top             =   1440
  114.       Width           =   930
  115.       _version        =   65536
  116.       _extentx        =   1640
  117.       _extenty        =   1058
  118.       _stockprops     =   0
  119.    End
  120.    Begin VB.Menu mnuFile 
  121.       Caption         =   "&File"
  122.       Begin VB.Menu mnuOpen 
  123.          Caption         =   "&Open..."
  124.       End
  125.       Begin VB.Menu mnuClose 
  126.          Caption         =   "&Close"
  127.       End
  128.       Begin VB.Menu mnuSep1 
  129.          Caption         =   "-"
  130.       End
  131.       Begin VB.Menu mnuInfo 
  132.          Caption         =   "&Info..."
  133.       End
  134.       Begin VB.Menu mnuSep2 
  135.          Caption         =   "-"
  136.       End
  137.       Begin VB.Menu mnuSave 
  138.          Caption         =   "&Save"
  139.       End
  140.       Begin VB.Menu mnuSaveAs 
  141.          Caption         =   "Save &As..."
  142.       End
  143.       Begin VB.Menu mnuSep3 
  144.          Caption         =   "-"
  145.       End
  146.       Begin VB.Menu mnuExit 
  147.          Caption         =   "E&xit"
  148.       End
  149.    End
  150.    Begin VB.Menu mnuVolume 
  151.       Caption         =   "&Volume"
  152.       Begin VB.Menu mnuIncreaseVolume 
  153.          Caption         =   "&Increase Volume (25%)"
  154.       End
  155.       Begin VB.Menu mnuDecreaseVolume 
  156.          Caption         =   "&Decrease Volume (25%)"
  157.       End
  158.    End
  159.    Begin VB.Menu mnuSpeed 
  160.       Caption         =   "&Speed"
  161.       Begin VB.Menu mnuIncreaseSpeed 
  162.          Caption         =   "&Increase Speed (10%)"
  163.       End
  164.       Begin VB.Menu mnuDecreaseSpeed 
  165.          Caption         =   "&Decrease Speed (10%)"
  166.       End
  167.       Begin VB.Menu mnuSep4 
  168.          Caption         =   "-"
  169.       End
  170.       Begin VB.Menu mnuNormalSpeed 
  171.          Caption         =   "&Normal Speed"
  172.       End
  173.    End
  174.    Begin VB.Menu mnuHelp 
  175.       Caption         =   "&Help"
  176.       Begin VB.Menu mnuAbout 
  177.          Caption         =   "&About..."
  178.       End
  179.    End
  180. Attribute VB_Name = "frmWave"
  181. Attribute VB_Creatable = False
  182. Attribute VB_Exposed = False
  183. ' All variables must be declared.
  184. Option Explicit
  185. ' Declaration of general variables.
  186. Dim gWavArray() As Integer
  187. Dim gArrayLength As Long
  188. Dim gRecordingInProgress As Boolean
  189. Dim gNormalSamplingRate As Long
  190. Private Sub cmdDelete_Click()
  191. ' Delete all the samples of the WAV file.
  192. TegoWav1.Delete 0, -1
  193. ' The WAV file is now empty, so reset the
  194. ' length of the WAV array to 0.
  195. gArrayLength = 0
  196. ReDim gWavArray(gArrayLength)
  197. ' Draw the graph.
  198. DrawGraph
  199. End Sub
  200. Private Sub cmdEndOfFile_Click()
  201. ' Seek to the end of file.
  202. TegoWav1.Seek -1
  203. End Sub
  204. Private Sub cmdPlay_Click()
  205. ' Play from the current playback position to the
  206. ' end of the WAV file, and don't wait while playing.
  207. TegoWav1.Play -1, -1, False
  208. End Sub
  209. Private Sub cmdRecord_Click()
  210.    ' Record from the current playback position
  211.    ' without limitation, and don't wait while
  212.    ' recording.
  213.    TegoWav1.Record -1, -1, False
  214.    ' If Record command was successful, set the
  215.    ' gRecordingInProgress variable to True, and
  216.    ' make the lblRecording label visible.
  217.    If TegoWav1.GetErrorCode = 0 Then
  218.       gRecordingInProgress = True
  219.       lblRecording.Visible = True
  220.    End If
  221. End Sub
  222. Private Sub cmdRewind_Click()
  223. ' Change the playback position to the beginning
  224. ' of the WAV file.
  225. TegoWav1.Seek 0
  226. End Sub
  227. Private Sub cmdstop_Click()
  228.   ' Stop the playback (or stop the recording).
  229.   TegoWav1.Stop
  230. End Sub
  231. Private Sub Form_Load()
  232.  TegoWav1.Visible = False
  233.  ' Initially, no WAV file is open, so we execute the
  234.  ' mnuClose_Click() procedure to disable various
  235.  ' controls.
  236.  mnuClose_Click
  237. End Sub
  238. Private Sub Form_Paint()
  239.   ' Draw the graph.
  240.   DrawGraph
  241. End Sub
  242. Private Sub mnuAbout_Click()
  243.    Dim Title
  244.    Dim Msg
  245.    Dim CR
  246.    CR = Chr(13) + Chr(10)
  247.    ' The title of the About message box.
  248.    Title = "About the Wave Program"
  249.    ' Prepare the message of the About message box.
  250.    Msg = "This program was written with Visual "
  251.    Msg = Msg + "Basic for Windows, using the "
  252.    Msg = Msg + "TegoSoft Wave OCX control. "
  253.    Msg = Msg + CR + CR
  254.    Msg = Msg + "The TegoSoft Wave OCX control "
  255.    Msg = Msg + "is part of the TegoSoft OCX Control "
  256.    Msg = Msg + "Kit - a collection of various OCX controls. "
  257.    Msg = Msg + CR + CR
  258.    Msg = Msg + "For more information about the "
  259.    Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  260.    Msg = Msg + "at:"
  261.    Msg = Msg + CR + CR
  262.    Msg = Msg + "TegoSoft Inc." + CR
  263.    Msg = Msg + "P.O. Box 389" + CR
  264.    Msg = Msg + "Bellmore, NY 11710"
  265.    Msg = Msg + CR + CR
  266.    Msg = Msg + "Phone: (516)783-4824"
  267.    ' Display the About message box.
  268.    MsgBox Msg, vbInformation, Title
  269. End Sub
  270. Private Sub mnuClose_Click()
  271. ' Close the WAV file.
  272. TegoWav1.Close
  273. ' No WAV file is currently open, so reset the
  274. ' length of the WAV array to 0.
  275. gArrayLength = 0
  276. ReDim gWavArray(gArrayLength)
  277. ' Initialize the gRecordingInProgress flag to False.
  278. gRecordingInProgress = False
  279. ' No WAV file is currently open, so we disable
  280. ' the Volume, Speed, Close, Info, Save,
  281. ' SaveAs, Play, Stop,Rewind, EndOfFile,
  282. ' Record and Delete controls.
  283. mnuIncreaseVolume.Enabled = False
  284. mnuDecreaseVolume.Enabled = False
  285. mnuIncreaseSpeed.Enabled = False
  286. mnuDecreaseSpeed.Enabled = False
  287. mnuNormalSpeed.Enabled = False
  288. mnuClose.Enabled = False
  289. mnuInfo.Enabled = False
  290. mnuSave.Enabled = False
  291. mnuSaveAs.Enabled = False
  292. cmdPlay.Enabled = False
  293. cmdstop.Enabled = False
  294. cmdRewind.Enabled = False
  295. cmdEndOfFile.Enabled = False
  296. cmdRecord.Enabled = False
  297. cmdDelete.Enabled = False
  298. ' Set the title of the program's window.
  299. Me.Caption = "The Wave Program"
  300. ' Draw the graph.
  301. DrawGraph
  302. End Sub
  303. Private Sub mnuDecreaseSpeed_Click()
  304. Dim SamplingRate
  305. ' Get the current sampling rate.
  306. SamplingRate = TegoWav1.GetSamplingRate
  307. ' Decrease SamplingRate by 10%.
  308. SamplingRate = SamplingRate * 0.9
  309. ' Set the mouse pointer to hourglass.
  310. Me.MousePointer = 11
  311. ' Set the new sampling rate.
  312. TegoWav1.SetSamplingRate SamplingRate
  313. ' Set the mouse pointer to default.
  314. Me.MousePointer = 0
  315. End Sub
  316. Private Sub mnuDecreaseVolume_Click()
  317.  ' Set the mouse pointer to hourglass.
  318.  Me.MousePointer = 11
  319.  ' Decrease the volume of all the samples of the
  320.  ' WAV file by 25%.
  321.  TegoWav1.ChangeVolume 0, -1, 0.75
  322.  ' Update the gWavArray array.
  323.  TegoWav1.WavFileToArray gWavArray(0), gArrayLength
  324.  ' Draw the graph.
  325.  DrawGraph
  326.  ' Set the mouse pointer to the default.
  327.  Me.MousePointer = 0
  328. End Sub
  329. Private Sub mnuExit_Click()
  330.    ' Terminate the program.
  331.    Unload Me
  332. End Sub
  333. Private Sub mnuIncreaseSpeed_Click()
  334. Dim SamplingRate As Long
  335. ' Get the current sampling rate.
  336. SamplingRate = TegoWav1.GetSamplingRate
  337. ' If SamplingRate is at its maximum value, tell
  338. ' the user and terminate this procedure.
  339. If SamplingRate = 44100 Then
  340.    MsgBox "Sampling Rate cannot be more than 44100 Hertz!"
  341.    Exit Sub
  342. End If
  343. ' Increase SamplingRate by 10%.
  344. SamplingRate = SamplingRate * 1.1
  345. ' If SamplingRate is greater than the maximum (44100),
  346. ' reset it to 44100.
  347. If SamplingRate > 44100 Then SamplingRate = 44100
  348. ' Set the mouse pointer to hourglass.
  349. Me.MousePointer = 11
  350. ' Set the new sampling rate.
  351. TegoWav1.SetSamplingRate SamplingRate
  352. ' Set the mouse pointer to the default.
  353. Me.MousePointer = 0
  354. End Sub
  355. Private Sub mnuIncreaseVolume_Click()
  356.  ' Set the mouse pointer to hourglass.
  357.  Me.MousePointer = 11
  358.  ' Increase the volume of all the samples of the
  359.  ' WAV file by 25%.
  360.  TegoWav1.ChangeVolume 0, -1, 1.25
  361.  ' Update the gWavArray array.
  362.  TegoWav1.WavFileToArray gWavArray(0), gArrayLength
  363.  ' Draw the graph.
  364.  DrawGraph
  365.  ' Set the mouse pointer to the default.
  366.  Me.MousePointer = 0
  367. End Sub
  368. Private Sub mnuInfo_Click()
  369. Dim Title
  370. Dim Msg
  371. Dim CRLF
  372. CRLF = Chr(13) + Chr(10)
  373. ' The title of the Info message box.
  374. Title = "WAV File Information"
  375. ' Prepare the message for the Info message box.
  376. Msg = "File Name: " + TegoWav1.GetWavFilename
  377. Msg = Msg + CRLF
  378. Msg = Msg + "File Length: " + Str(TegoWav1.GetLength) + " samples."
  379. Msg = Msg + CRLF
  380. Msg = Msg + "Sampling Rate: " + Str(TegoWav1.GetSamplingRate) + " Hz."
  381. Msg = Msg + CRLF
  382. Msg = Msg + "Number of Bits Per Sample: " + Str(TegoWav1.GetNumBits)
  383. Msg = Msg + CRLF
  384. Msg = Msg + "Number of Channels: " + Str(TegoWav1.GetNumChannels)
  385. ' Display the Info message box.
  386. MsgBox Msg, vbInformation, Title
  387. End Sub
  388. Private Sub mnuNormalSpeed_Click()
  389. ' Set the mouse pointer to hourglass.
  390. Me.MousePointer = 11
  391. ' Set the sampling rate of the WAV file to the
  392. ' normal sampling rate.
  393. TegoWav1.SetSamplingRate gNormalSamplingRate
  394. ' Set the mouse pointer to default.
  395. Me.MousePointer = 0
  396. End Sub
  397. Private Sub mnuOpen_Click()
  398.     ' Set an error trap to detect the clicking
  399.     ' of the Cancel key of the Open dialog box.
  400.     On Error GoTo OpenError
  401.     ' Fill the items of the File Type list box of
  402.     ' the Open dialog box.
  403.     CommonDialog1.Filter = "All Files (*.*)|*.*|Wave Files (*.wav)|*.wav"
  404.     ' Set the default File Type to Wave Files (*.wav).
  405.     CommonDialog1.FilterIndex = 2
  406.     ' Display the Open dialog box.
  407.     CommonDialog1.Action = 1
  408.     ' Remove the error trap.
  409.     On Error GoTo 0
  410.     ' Open the WAV file that the user selected.
  411.     TegoWav1.Open CommonDialog1.filename
  412.     ' If Open command failed, exit this procedure.
  413.     If TegoWav1.GetErrorCode <> 0 Then
  414.        MsgBox "Cannot open " + CommonDialog1.filename, 0, "ERROR"
  415.        mnuClose_Click
  416.        Exit Sub
  417.     End If
  418.     ' Set the mouse pointer to hourglass.
  419.     Me.MousePointer = 11
  420.     ' Update the WAV array with the samples of the WAV file.
  421.     gArrayLength = TegoWav1.GetLength() * TegoWav1.GetNumChannels()
  422.     ReDim gWavArray(gArrayLength)
  423.     TegoWav1.WavFileToArray gWavArray(0), gArrayLength
  424.    ' Set the mouse pointer to default.
  425.     Me.MousePointer = 0
  426.     ' If updating of the WAV array failed, close
  427.     ' the WAV file.
  428.     If TegoWav1.GetErrorCode > 0 Then
  429.        mnuClose_Click
  430.        Exit Sub
  431.     End If
  432.       
  433.     ' Store the sampling rate of the WAV file.
  434.     gNormalSamplingRate = TegoWav1.GetSamplingRate
  435.     ' Display the name of the WAV file (without the path).
  436.     Me.Caption = "The Wave Program - " + CommonDialog1.FileTitle
  437.     ' Draw the graph
  438.     DrawGraph
  439.     ' A WAV file is now open, so enable
  440.     ' the Volume, Speed, Close, Info, Save,
  441.     ' SaveAs, Play, Stop, Rewind, EndOfFile,
  442.     ' Record, and Delete controls.
  443.     mnuIncreaseVolume.Enabled = True
  444.     mnuDecreaseVolume.Enabled = True
  445.     mnuIncreaseSpeed.Enabled = True
  446.     mnuDecreaseSpeed.Enabled = True
  447.     mnuNormalSpeed.Enabled = True
  448.     mnuClose.Enabled = True
  449.     mnuInfo.Enabled = True
  450.     mnuSave.Enabled = True
  451.     mnuSaveAs.Enabled = True
  452.     cmdPlay.Enabled = True
  453.     cmdstop.Enabled = True
  454.     cmdRewind.Enabled = True
  455.     cmdEndOfFile.Enabled = True
  456.     cmdRecord.Enabled = True
  457.     cmdDelete.Enabled = True
  458.     ' Exit the procedure.
  459.     Exit Sub
  460. OpenError:
  461.     ' The user clicked the Cancel button of the
  462.     ' Open File dialog box.
  463.     Exit Sub
  464. End Sub
  465. Private Sub mnuSave_Click()
  466. ' Save the WAV file to the disk.
  467. TegoWav1.Save
  468. End Sub
  469. Private Sub mnuSaveAs_Click()
  470.     Dim Msg, Answer
  471.     ' Set an error trap to detect the clicking
  472.     ' of the Cancel key of the Save As dialog box.
  473.     On Error GoTo SaveAsError
  474.     ' Fill the items of the File Type list box of
  475.     ' the Open dialog box.
  476.     CommonDialog1.Filter = "All Files (*.*)|*.*|Wave Files (*.wav)|*.wav"
  477.     ' Set the default File Type to Wave Files (*.wav).
  478.     CommonDialog1.FilterIndex = 2
  479.     ' Display the Save As dialog box.
  480.     CommonDialog1.Action = 2
  481.     ' Remove the error trap.
  482.     On Error GoTo 0
  483.     ' If the file specified by the user exists, and its
  484.     ' size is not zero, ask the user if to overwrite it.
  485.     If Dir(CommonDialog1.filename) <> "" Then
  486.        Msg = CommonDialog1.filename + Chr(13)
  487.        Msg = Msg + "This WAV file already exists." + Chr(13) + Chr(13)
  488.        Msg = Msg + "Replace existing file?"
  489.        Answer = MsgBox(Msg, vbExclamation + vbYesNo)
  490.        If Answer = vbNo Then
  491.           Exit Sub
  492.        End If
  493.     End If
  494.     ' Set the mouse pointer to hourglass.
  495.     Me.MousePointer = 11
  496.     ' Issue a SaveAs command.
  497.     TegoWav1.SaveAs CommonDialog1.filename
  498.     ' Set the mouse cursor to default.
  499.     Me.MousePointer = 0
  500.     ' If the SaveAs command failed, tell the user,
  501.     ' and abort this procedure.
  502.     If TegoWav1.GetErrorCode <> 0 Then
  503.        MsgBox "Cannot save " + CommonDialog1.filename, 0, "ERROR"
  504.        Exit Sub
  505.     End If
  506.     ' Set the title of the Window.
  507.     Me.Caption = "The Wave Program - " + CommonDialog1.FileTitle
  508.     ' Exit the procedure.
  509.     Exit Sub
  510. SaveAsError:
  511.     ' The user clicked the Cancel button.
  512.     Exit Sub
  513. End Sub
  514. Private Sub swExit_Click()
  515.    Dim Title
  516.    Dim Question
  517.    Dim Response
  518.    ' If the user turned the swExit switch OFF,
  519.    ' confirm that the user wants to exit the
  520.    ' program, and if so, exit the program.
  521.    If swExit.Value = False Then
  522.       Title = "Exit Program"
  523.       Question = "Are you sure you want to exit?"
  524.       Response = MsgBox(Question, vbYesNo + vbQuestion, Title)
  525.       If Response = vbYes Then
  526.          Unload Me
  527.       Else
  528.          swExit.Value = True
  529.       End If
  530.    End If
  531. End Sub
  532. Private Sub TegoWav1_Done(ByVal NotifyCode As Integer)
  533.     ' If current playback position is at the end
  534.     ' of the WAV file, change the playback position
  535.     ' to the beginning of the WAV file.
  536.     If TegoWav1.GetPosition = TegoWav1.GetLength Then
  537.        TegoWav1.Seek 0
  538.     End If
  539.     ' Has recording just stopped?
  540.     If gRecordingInProgress = True Then
  541.        
  542.        ' Recording is now not in progress.
  543.        gRecordingInProgress = False
  544.        
  545.        ' Hide the lblRecording label.
  546.        lblRecording.Visible = False
  547.        
  548.        ' Update the gWavArray array.
  549.        Me.MousePointer = 11
  550.        gArrayLength = TegoWav1.GetLength() * TegoWav1.GetNumChannels()
  551.        ReDim gWavArray(gArrayLength)
  552.        TegoWav1.WavFileToArray gWavArray(0), gArrayLength
  553.        Me.MousePointer = 0
  554.        ' Draw the graph.
  555.        DrawGraph
  556.     End If
  557. End Sub
  558. Public Sub DrawGraph()
  559.     Dim I
  560.     Dim Sample
  561.     Dim MidPoint
  562.     Dim Increment
  563.     Dim SampleNumber
  564.     ' Clear the current graph.
  565.     Cls
  566.     ' Calculate the midpoint of the form
  567.     MidPoint = Me.ScaleHeight / 2
  568.     ' Draw a horizontal line in the middle of the
  569.     ' form (the x-axis).
  570.     Line (0, MidPoint)-(Me.ScaleWidth, MidPoint)
  571.     ' If the WAV array is empty, terminate this procedure.
  572.     If gArrayLength = 0 Then
  573.        Exit Sub
  574.     End If
  575.     ' Display the bars of the graph.
  576.     Increment = gArrayLength / Me.ScaleWidth
  577.     For I = 0 To Me.ScaleWidth Step 1
  578.         SampleNumber = I * Increment
  579.         Sample = gWavArray(SampleNumber)
  580.         If TegoWav1.GetNumBits = 8 Then
  581.            Line (I, MidPoint)-(I, MidPoint - Sample + 128)
  582.         Else
  583.            Line (I, MidPoint)-(I, MidPoint - (Sample / 260))
  584.         End If
  585.     Next I
  586. End Sub
  587.